﻿<UserControl x:Class="BrokenHouse.Windows.VisualStudio.Design.Wizard.WizardControlOptions"
             x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:bh="http://www.brokenhouse.co.uk/wpf"
             xmlns:controls="clr-namespace:BrokenHouse.Windows.VisualStudio.Design"
             xmlns:local="clr-namespace:BrokenHouse.Windows.VisualStudio.Design.Wizard"
             xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase" 
             xmlns:resources="clr-namespace:BrokenHouse.Windows.VisualStudio.Design.Resources"
             Focusable="True"
             FocusManager.IsFocusScope="True" >
    
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static local:WizardControlOptionsCommands.NewAeroPage}" CanExecute="OnCanExecute" Executed="OnNewAreoPage"/>
        <CommandBinding Command="{x:Static local:WizardControlOptionsCommands.NewContentPage}" CanExecute="OnCanExecute" Executed="OnNewContentPage"/>
        <CommandBinding Command="{x:Static local:WizardControlOptionsCommands.NewTitlePage}" CanExecute="OnCanExecute" Executed="OnNewTitlePage"/>
        <CommandBinding Command="{x:Static local:WizardControlOptionsCommands.DeletePage}" CanExecute="OnCanExecute" Executed="OnDeletePage"/>
        <CommandBinding Command="{x:Static local:WizardControlOptionsCommands.MovePageBackwards}" CanExecute="OnCanExecute" Executed="OnMovePageBackwards"/>
        <CommandBinding Command="{x:Static local:WizardControlOptionsCommands.MovePageForwards}" CanExecute="OnCanExecute" Executed="OnMovePageForwards"/>
    </UserControl.CommandBindings>
    
    <UserControl.Resources>
        <bh:IsNullOrEmptyConverter x:Key="IsNullOrEmptyConverter"/>

        <Style x:Key="ToolBarStyle" TargetType="{x:Type ToolBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToolBar}">
                        <Border x:Name="MainPanelBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3,3,3,3" Padding="{TemplateBinding Padding}">
                            <DockPanel KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
                                <ContentPresenter HorizontalAlignment="Center" Margin="0" x:Name="ToolBarHeader" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header"/>
                                <ToolBarPanel Margin="2" x:Name="PART_ToolBarPanel" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" IsItemsHost="true"/>
                            </DockPanel>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <DataTemplate x:Key="MainTemplate">
            <DockPanel MaxHeight="{Binding MaxHeight, diag:PresentationTraceSources.TraceLevel=High}">

                <DockPanel.BitmapEffect>
                    <DropShadowBitmapEffect ShadowDepth="2"/>
                </DockPanel.BitmapEffect>

                <Border DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="1" CornerRadius="5" Background="White" Margin="1"
                        SnapsToDevicePixels="True">
                    <Border BorderBrush="LightGray" BorderThickness="1" CornerRadius="4" Background="White">
                        <StackPanel>
                            <TextBlock FontSize="10" Text="Manage" Margin="2,0,2,1" SnapsToDevicePixels="True"/>
                            <ToolBar Band="1" AllowDrop="False" Style="{StaticResource ToolBarStyle}">
                                <controls:PopupButton x:Name="PART_ClassicButton"  ToolTip="{x:Static resources:Strings.Options_AddPageTooltip}">
                                    <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/NewBlank.ico"
                                                   SnapsToDevicePixels="True" Width="16" Height="16"/>
                                    <controls:PopupButton.PopupItems>
                                        <MenuItem Header="Content Page" Command="{x:Static local:WizardControlOptionsCommands.NewContentPage}"
                                                  ToolTip="{x:Static resources:Strings.Options_AddContentPageTooltip}">
                                            <MenuItem.Icon>
                                                <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/NewClassicContent.ico" 
                                                               SnapsToDevicePixels="True" Width="16" Height="16"/>
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem Header="Title Page" Command="{x:Static local:WizardControlOptionsCommands.NewTitlePage}"
                                                  ToolTip="{x:Static resources:Strings.Options_AddTitlePageTooltip}">
                                            <MenuItem.Icon>
                                                <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/NewClassicTitle.ico" 
                                                               SnapsToDevicePixels="True"  Width="16" Height="16"/>
                                            </MenuItem.Icon>
                                        </MenuItem>
                                    </controls:PopupButton.PopupItems>
                                </controls:PopupButton>
                                
                                <Button ToolBar.OverflowMode="Never" x:Name="PART_AeroButton" 
                                        Command="{x:Static local:WizardControlOptionsCommands.NewAeroPage}"
                                        Visibility="Collapsed"
                                        ToolTip="{x:Static resources:Strings.Options_AddAeroPageTooltip}">
                                    <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/NewAero.ico"
                                                   SnapsToDevicePixels="True"  Width="16" Height="16"/>
                                </Button>
                                <Button ToolBar.OverflowMode="Never" Command="{x:Static local:WizardControlOptionsCommands.DeletePage}"
                                        ToolTip="{x:Static resources:Strings.Options_DeletePage}">
                                    <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/Delete.ico"
                                                   SnapsToDevicePixels="True"  Width="16" Height="16"/>
                                </Button>
                                <Button ToolBar.OverflowMode="Never"  Command="{x:Static local:WizardControlOptionsCommands.MovePageBackwards}"
                                        ToolTip="{x:Static resources:Strings.Options_MoveTowardsBegining}">
                                    <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/BringToFront.ico"
                                                   SnapsToDevicePixels="True" Width="16" Height="16"/>
                                </Button>
                                <Button ToolBar.OverflowMode="Never"  Command="{x:Static local:WizardControlOptionsCommands.MovePageForwards}"
                                        ToolTip="{x:Static resources:Strings.Options_MoveTowardsEnd}">
                                    <bh:ActiveIcon Source="/BrokenHouse.Windows.VisualStudio.Design;component/Resources/SendToBack.ico"
                                                   SnapsToDevicePixels="True" Width="16" Height="16"/>
                                </Button>
                            </ToolBar>
                        </StackPanel>
                    </Border>
                </Border>

                <Border x:Name="PART_Navigator" Margin="1" BorderBrush="Gray" BorderThickness="1" CornerRadius="5" Background="White"
                    SnapsToDevicePixels="True">
                    <Border BorderBrush="LightGray" BorderThickness="1" CornerRadius="4" Background="White">
                        <DockPanel>
                            <DockPanel DockPanel.Dock="Top">
                                <TextBlock FontSize="10" DockPanel.Dock="Right" Text="{Binding Path=Summary}" Margin="2,0,2,0"/>
                                <TextBlock FontSize="10" Text="Navigate" Margin="2,0,2,0"/>
                            </DockPanel>
                            <ListBox ItemsSource="{Binding PageItemCollection}" SelectedItem="{Binding Path=ActivePageItem}" BorderThickness="0"
                                     HorizontalContentAlignment="Stretch" Margin="1" SnapsToDevicePixels="True" ScrollViewer.CanContentScroll="False">
                                <ListBox.ItemContainerStyle>
                                    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                                        <Setter Property="Padding" Value="1"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                    <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="IsSelected" Value="true">
                                                            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                                                        </Trigger>
                                                        <Trigger Property="IsEnabled" Value="false">
                                                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Rectangle Stroke="Black" Margin="1" SnapsToDevicePixels="True"
                                           Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=DataContext.ThumbnailWidth}"
                                           Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=DataContext.ThumbnailHeight}">
                                            <Rectangle.Fill>
                                                <VisualBrush Visual="{Binding View}" Stretch="Fill" AutoLayoutContent="False" />
                                            </Rectangle.Fill>
                                        </Rectangle>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </DockPanel>
                    </Border>
                </Border>
            </DockPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=IsAeroWizard}" Value="True">
                    <Setter TargetName="PART_AeroButton" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="PART_ClassicButton" Property="Visibility" Value="Collapsed"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </UserControl.Resources>
    
    <!-- Now the layout -->
    <ContentPresenter ContentTemplate="{StaticResource MainTemplate}" Content="{Binding .}"/>

</UserControl>
